<?php
class SettingsController extends AppController {
	var $name = 'Settings';
	var $helpers = array('Html');
	var $components = array('Init', 'Param');
        var $uses = array('Setting');

	function beforeFilter() {
		if (!$this->Session->read('admin')) {
			$this->redirect('/login');
		}
		else {
			$this->Init->startup($this);
			$this->Admin = $this->Init->init();

			$this->set('dashboard',0);
			$this->set('content',0);
			$this->set('products',0);
			$this->set('component',0);
			$this->set('system',1);

			$this->set('title','Settings Management');
			$this->set('sub_title', $this->Param->getAction($this->params));
  		}
	}

	function index(){
		$settings = $this->Setting->find('all');
		$this->set('settings',$settings);
	}

	function edit($id = null){
		$this->helpers[] = 'Ck';
		$id = $this->Param->getID($this->params);

		if (isset($this->data)) {

			if ($this->Setting->save($this->data)) {
				$this->Session->setFlash('Done successfully!');
				$this->redirect('/settings');
			}

		}
		else {
			if (isset($id) && ($id > 0)) {
				$this->data = $this->Setting->find('first',array(
					'conditions' => array('Setting.id' => $id)
				));

			}
		}
	}

}
?>